package com.yunhe.tianhe.rentcars.controller.system;


import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dto.JSONResponse;
import com.yunhe.tianhe.rentcars.entity.system.MemberLevel;
import com.yunhe.tianhe.rentcars.service.system.MemberLevelService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

/**
 * # @Author: 贾波
 * # @Time: 2017-11-24-下午 4:16
 * # Description:
 */
@Controller
@RequestMapping("/memberLevel")
public class MemberLevelController {
    @Autowired
    private MemberLevelService memberLevelService;
    
    @RequestMapping
    public String list(){
        return "/system/memberLevel/list";
    }

    @RequestMapping("/listData")
    @ResponseBody
    public Pageable<MemberLevel> findPage(Long offset, Long limit,String levelName){
        return memberLevelService.findPageList(offset, limit,levelName);
    }

    @RequestMapping("/add")
    public String add(){
        return "/system/memberLevel/add";
    }

    @RequestMapping("/save")
    @ResponseBody
    public JSONResponse save(MemberLevel MemberLevel){
        Long id = memberLevelService.save(MemberLevel);
        return JSONResponse.success("保存成功",id);
    }

    @RequestMapping("/delete")
    @ResponseBody
    public JSONResponse delete(String ids){
        memberLevelService.deleteBatch(ids);
        return JSONResponse.success("删除成功");
    }

    @RequestMapping("/edit")
    public String edit(Long id, HttpServletRequest req){
        MemberLevel memberLevel = memberLevelService.findOne(id);
        HttpSession session = req.getSession();
        session.setAttribute("memberLevel",memberLevel);
        return  "/system/memberLevel/edit";
    }

    @RequestMapping("/update")
    @ResponseBody
    public JSONResponse update(MemberLevel MemberLevel){
        Long code = memberLevelService.update(MemberLevel);
        return JSONResponse.success("修改成功",code);
    }
}
